﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Services.Localization;
    using DotNetNuke.Services.Search;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Globalization;
    using System.Web;
    using System.Xml;

    public class ProductListController : BasePortController, ISearchable
    {
        public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {
            ProductController controller = new ProductController();
            LocaleCollection supportedLocales = DotNetNuke.Services.Localization.Localization.GetSupportedLocales();
            string lang = "";
            bool flag = false;
            Hashtable moduleSettings = PortalSettings.GetModuleSettings(ModInfo.ModuleID);
            if (Conversions.ToString(moduleSettings["chkIndexProducts"]) != "")
            {
                flag = !Conversions.ToBoolean(moduleSettings["chkIndexProducts"]);
            }
            else
            {
                flag = true;
            }
            SearchItemInfoCollection infos2 = new SearchItemInfoCollection();
            if (!flag)
            {
                int num5 = supportedLocales.Count - 1;
                for (int i = 0; i <= num5; i++)
                {
                    DictionaryEntry entry = supportedLocales[i];
                    CultureInfo info = CultureInfo.CreateSpecificCulture(((Locale) entry.Value).Code);
                    entry = supportedLocales[i];
                    lang = ((Locale) entry.Value).Code;
                    int pageIndex = 1;
                    int pagesize = 500;
                    for (ArrayList list = controller.GetProductList(ModInfo.PortalID, -1, lang, "", false, pageIndex, pagesize, false, false); (list.Count > 0) & (pageIndex <= 20); list = controller.GetProductList(ModInfo.PortalID, -1, lang, "", false, pageIndex, pagesize, false, false))
                    {
                        IEnumerator enumerator=null;
                        try
                        {
                            enumerator = list.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                DateTime createdDate;
                                ProductListInfo current = (ProductListInfo) enumerator.Current;
                                int nullInteger = Null.NullInteger;
                                nullInteger = int.Parse(current.CreatedByUser);
                                string title = HttpUtility.HtmlDecode(current.ProductName);
                                string xMLData = current.XMLData;
                                string str4 = "";
                                XmlDataDocument document = new XmlDataDocument();
                                if (xMLData != "")
                                {
                                    XmlNode node;
                                    IEnumerator enumerator2=null;
                                    IEnumerator enumerator3=null;
                                    IEnumerator enumerator4=null;
                                    document.LoadXml(xMLData);
                                    XmlNodeList list2 = document.SelectNodes("genxml/textbox");
                                    try
                                    {
                                        enumerator2 = list2.GetEnumerator();
                                        while (enumerator2.MoveNext())
                                        {
                                            node = (XmlNode) enumerator2.Current;
                                            str4 = str4 + node.InnerText + " ";
                                        }
                                    }
                                    finally
                                    {
                                        if (enumerator2 is IDisposable)
                                        {
                                            (enumerator2 as IDisposable).Dispose();
                                        }
                                    }
                                    list2 = document.SelectNodes("genxml/dropdownlist");
                                    try
                                    {
                                        enumerator3 = list2.GetEnumerator();
                                        while (enumerator3.MoveNext())
                                        {
                                            node = (XmlNode) enumerator3.Current;
                                            str4 = str4 + node.InnerText + " ";
                                        }
                                    }
                                    finally
                                    {
                                        if (enumerator3 is IDisposable)
                                        {
                                            (enumerator3 as IDisposable).Dispose();
                                        }
                                    }
                                    list2 = document.SelectNodes("genxml/radiobuttonlist");
                                    try
                                    {
                                        enumerator4 = list2.GetEnumerator();
                                        while (enumerator4.MoveNext())
                                        {
                                            node = (XmlNode) enumerator4.Current;
                                            str4 = str4 + node.InnerText + " ";
                                        }
                                    }
                                    finally
                                    {
                                        if (enumerator4 is IDisposable)
                                        {
                                            (enumerator4 as IDisposable).Dispose();
                                        }
                                    }
                                }
                                string content = HtmlUtils.Shorten(HtmlUtils.Clean(HttpUtility.HtmlDecode(title + ": " + current.Manufacturer + ": " + current.ProductRef + ": " + current.Description + " " + current.Summary + " " + str4), false), ((title.Length + current.Description.Length) + current.Summary.Length) + 3, "...");
                                if (DateTime.Compare(current.ModifiedDate, Null.NullDate) == 0)
                                {
                                    createdDate = current.CreatedDate;
                                }
                                else
                                {
                                    createdDate = current.ModifiedDate;
                                }
                                SearchItemInfo info3 = new SearchItemInfo(title, title, nullInteger, createdDate, ModInfo.ModuleID, current.ProductID.ToString() + current.Lang, content, "ProdID=" + current.ProductID.ToString());
                                infos2.Add(info3);
                            }
                        }
                        finally
                        {
                            if (enumerator is IDisposable)
                            {
                                (enumerator as IDisposable).Dispose();
                            }
                        }
                        pageIndex++;
                    }
                }
            }
            return infos2;
        }
    }
}

